/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.util;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.serialize.JSONDeserializer;
import org.bson.types.ObjectId;

/**
 * @author THINK
 * @version v1.0
 * @className ObjectId ObjectIdDeSerizlizer
 * @description _id的序列化反转换器
 * @date 2024/6/12 14:11
 **/
public class ObjectIdDeSerizlizer implements JSONDeserializer<ObjectId> {
    private final Class<? extends ObjectId> ObjectIdClass;

    public ObjectIdDeSerizlizer(Class<? extends ObjectId> ObjectIdClass) {
        this.ObjectIdClass = ObjectIdClass;
    }

    @Override
    public ObjectId deserialize(JSON json) {
        JSONObject jsonObject = (JSONObject)json;
        if(jsonObject.containsKey("_id")){
            return new ObjectId(jsonObject.getStr("_id"));
        }
        return null;
    }
}
